package com.hc.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hc.entity.House;
import com.hc.service.HouseService;
import com.hc.serviceimp.HouseServiceImpl;

@WebServlet("/AddHouseServlet")
public class AddHouseServlet extends HttpServlet {

	//获取service层对象
	HouseService hService=new HouseServiceImpl();
	
    public AddHouseServlet() {
        super();
      
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		
		//进入添加页面
		if (action.equals("toAdd")) {
			
			request.getRequestDispatcher("/WEB-INF/house/add.jsp").forward(request, response);
		}
		
		//添加房屋信息
		if (action.equals("add")) {
			
			String parameter1 = request.getParameter("diqu");
			String parameter2 = request.getParameter("xiaoqu");
			int parameter3 = Integer.parseInt(request.getParameter("danyuan"));
			int paramete4 = Integer.parseInt(request.getParameter("louceng"));
			int paramete5 = Integer.parseInt(request.getParameter("menpai"));
			int paramete6 = Integer.parseInt(request.getParameter("mianji"));
			String parameter7 = request.getParameter("chaoxiang");
			String parameter8 = request.getParameter("zhaungxiu");
			String parameter9 = request.getParameter("shaungqi");
			int parameter10 = Integer.parseInt(request.getParameter("renshu"));
			String parameter11 = request.getParameter("sheshi");
			int parameter12 = Integer.parseInt(request.getParameter("jiage"));
			String parameter13 = request.getParameter("zhuangtai");
			String parameter14 = request.getParameter("xinxi");
			String parameter15 = request.getParameter("tainjia");
			String parameter16 = request.getParameter("gengxin");
			
			House house = new House(0, parameter1, parameter2, parameter3, paramete4, paramete5, paramete6, parameter7, parameter8, parameter9, parameter10, parameter11, parameter12, parameter13, parameter14, parameter15, parameter16);
			
			hService.addHouse(house);
			
			request.getRequestDispatcher("").forward(request, response);
		}
		
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
